$(window).on("load", function () {
    if (localStorage) {
        var MODE = localStorage.getItem("mode");
        if (MODE) {
            $("body").prop("id", MODE);
            $(".switch-checkbox").prop("checked", true);
        } else {
            localStorage.setItem("mode", "");
        }
    }
    function placeholderSupport() {
        return 'placeholder' in document.createElement('input');
    }
    if (!placeholderSupport()) {
        $("[placeholder]").each(function () {
            var _this = $(this);
            var left = _this.css("padding-left");
            _this.parent().append('<span class="placeholder" data-type="placeholder" style="left: ' + left + '">' + _this.attr("placeholder") + '</span>');
            if (_this.val() != "") {
                _this.parent().find("span.placeholder").hide();
            }
            else {
                _this.parent().find("span.placeholder").show();
            }
        }).on("focus", function () {
            $(this).parent().find("span.placeholder").hide();
        }).on("blur", function () {
            var _this = $(this);
            if (_this.val() != "") {
                _this.parent().find("span.placeholder").hide();
            }
            else {
                _this.parent().find("span.placeholder").show();
            }
        });
        $("span.placeholder").on("click", function () {
            $(this).hide();
            $(this).siblings("[placeholder]").trigger("click");
            $(this).siblings("[placeholder]").trigger("focus");
        })
    }
    $(document).click(function () {
        $(".menu-layer").stop(true).fadeOut();
        $(".menu-list").stop(true).animate({ "left": "-305px" }, 200);
        scrolling("", "");
    })
    $("#go-up").click(function () {
        $(this).addClass("active");
        $("html, body").animate({
            scrollTop: 0
        }, 500);
        var _this = this;
        setTimeout(function () {
            $(_this).removeClass("active");
        }, 500);
    })
    goUp()
    $(window).scroll(function () {
        goUp()
    })
    $(".menu-btn").click(function (event) {
        event.stopPropagation();
        var left = $(".menu-list").css("left");
        if (left === "-305px") {
            scrolling("hidden", "fixed");
            $(".menu-list").click(function (event) {
                event.stopPropagation();
            })
            $(".menu-layer").stop(true).fadeIn();
            $(".menu-list").stop(true).animate({ "left": "0" }, 300);
        } else {
            scrolling("", "");
            $(".menu-list").stop(true).animate({ "left": "-305px" }, 200);
            $(".menu-layer").stop(true).fadeOut();
        }
    })
    $(".switch-checkbox, .right-logo").click(function () {
        if ($("body").prop("id")) {
            $("body").prop("id", "");
            if (localStorage) localStorage.setItem("mode", "");
        } else {
            $("body").prop("id", "night");
            if (localStorage) localStorage.setItem("mode", "night");
        }
    })
})

function goUp() {
    $(this).scrollTop() > 110 ? $("#go-up").fadeIn(200) : $("#go-up").fadeOut(200);
}

function scrolling(overflow, position) {
    $("body").css({ "overflow": overflow, "position": position });
}